struct Solution {}

fn main() {}

impl Solution {
    pub fn backspace_compare(s: String, t: String) -> bool {
        let s_new = Self::backspace(s);
        let t_new = Self::backspace(t);
        s_new == t_new
    }

    fn backspace(s: String) -> String {
        let mut ret: Vec<char> = vec![];
        for c in s.chars() {
            match c {
                '#' => Self::delete_last(&mut ret),
                _ => ret.push(c),
            }
        }
        ret.iter().collect::<String>()
    }

    fn delete_last(v: &mut Vec<char>) {
        if !v.is_empty() {
            v.remove(v.len() - 1);
        }
    }
}